package com.alibaba.citrus.ots.unified.inventory.functions.consignmentOrder;

import com.epoch.app.otsunifiedinventory.dto.request.ConsignmentOrderWriteCreateRequest;
import com.epoch.app.otsunifiedinventory.sdo.ConsignmentOrderLineSDO;
import com.epoch.app.otsunifiedinventory.sdo.ConsignmentOrderSDO;

import java.util.List;
import java.util.stream.Collectors;

public class ConsignmentOrderFactory {

    private ConsignmentOrderSDO consignmentOrderSDO;

    public static ConsignmentOrderEntity createConsignmentOrder(ConsignmentOrderWriteCreateRequest request) {
        ConsignmentOrderSDO consignmentOrderSDO = new ConsignmentOrderSDO();
        consignmentOrderSDO.setOuterDeliveryOrderId(request.getOuterDeliveryOrderId());
        consignmentOrderSDO.setOuterSalesOrderId(request.getOuterSalesOrderId());
        consignmentOrderSDO.setSalesOrderId(request.getSalesOrderId());
        consignmentOrderSDO.setOuterStoOrderId(request.getOuterStoOrderId());
        consignmentOrderSDO.setStoOrderId(request.getStoOrderId());
        consignmentOrderSDO.setSalesOrgId(request.getSalesOrgId());
        consignmentOrderSDO.setCreator(request.getCreator());
        consignmentOrderSDO.setCreatDate(request.getCreatDate());
        consignmentOrderSDO.setModifier(request.getModifier());
        consignmentOrderSDO.setModifidDate(request.getModifidDate());
        consignmentOrderSDO.setDeliveryDate(request.getDeliveryDate());
        consignmentOrderSDO.setFeatures(request.getFeatures());
        List<ConsignmentOrderLineSDO> orderLineSDOS = request.getConsignmentOrderLineRequest().stream().map(orderLineRequest -> {
            ConsignmentOrderLineSDO orderLineSDO = new ConsignmentOrderLineSDO();
            orderLineSDO.setOuterOrderLineId(orderLineRequest.getOuterOrderLineId());
            orderLineSDO.setOuterSoLineId(orderLineRequest.getOuterSoLineId());
            orderLineSDO.setSoLineId(orderLineRequest.getSoLineId());
            orderLineSDO.setOuterStoLineId(orderLineRequest.getOuterStoLineId());
            orderLineSDO.setStoLineId(orderLineRequest.getStoLineId());
            orderLineSDO.setScItemId(orderLineRequest.getScItemId());
            orderLineSDO.setQty(orderLineRequest.getQty());
            orderLineSDO.setPodStatus(orderLineRequest.getPodStatus());
            orderLineSDO.setPodQty(orderLineRequest.getPodQty());
            orderLineSDO.setFactoryCode(orderLineRequest.getFactoryCode());
            orderLineSDO.setInventoryCode(orderLineRequest.getInventoryCode());
            orderLineSDO.setCreator(request.getCreator());
            orderLineSDO.setModifier(request.getModifier());
            orderLineSDO.setSaleUnit(orderLineRequest.getSaleUnit());
            orderLineSDO.setBasicQuantity(orderLineRequest.getBasicQuantity());
            return orderLineSDO;
        }).collect(Collectors.toList());
        consignmentOrderSDO.setConsignmentOrderLineSDOS(orderLineSDOS);
        return ConsignmentOrderEntity.of(consignmentOrderSDO);
    }

    public static ConsignmentOrderEntity deleteConsignmentOrder(ConsignmentOrderSDO query) {
        return ConsignmentOrderEntity.of(query);
    }
}
